package demo8;

import java.sql.SQLException;
import java.util.Scanner;

public class Main {
    public static void menu() {
        System.out.println("1. 注册");
        System.out.println("2. 登录");
        System.out.println("3. 删除");
        System.out.println("4. 修改");
        System.out.println("5. 退出");
    }
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        UserMain userMain = new UserMain();
        System.out.println("欢迎来到系统");
        while (true){
            menu();
            Scanner  scanner = new Scanner(System.in);
            System.out.println("请选择：");
            int choice = scanner.nextInt();
            switch (choice){
                case 1:
                    System.out.println("注册新用户");
                    System.out.println("请输入用户名：");
                    String username = scanner.next();
                    System.out.println("请输入密码：");
                    String password = scanner.next();
                    int i=userMain.addUser(username,password);
                    if (i>0){
                        System.out.println("注册成功！");
                    }else {
                        System.out.println("注册失败！");
                    }
                    break;
                case 2:
                    System.out.println("请输入用户名：");
                    String name = scanner.next();
                    System.out.println("请输入密码：");
                    String pwd = scanner.next();
                    Users users = userMain.login(name,pwd);
                    if (users!=null){
                        System.out.println("登录成功！");
                    }else {
                        System.out.println("登录失败！");
                    }
                    break;
                case 3:
                    System.out.println("请输入id进行删除：");
                    int id = scanner.nextInt();
                    int m = userMain.deleteUser(id);
                    if (m>0){
                        System.out.println("删除成功！");
                    }else {
                        System.out.println("删除失败！");
                    }
                    break;
                case 4:
                    System.out.println("请输入id进行修改：");
                    int id1 = scanner.nextInt();
                    System.out.println("请输入用户名");
                    String username1 = scanner.next();
                    int n = userMain.updateUser(id1,username1);
                    if (n>0){
                        System.out.println("修改成功！");
                    }else {
                        System.out.println("修改失败！");
                    }
                    break;
                case 5:
                    System.out.println("退出系统");
                    System.exit(0);
                    break;
                default:
                    System.out.println("输入错误！请重新输入:");
            }

        }
    }
}
